< previous page page_16 next page >

Page 16
z0036-01.gif
Figure 1.7
Output from the statement
Circle (50, 50), 30,, 
p / 6, p * 0.75.
Unfortunately 0 = 0, so the Circle method cannot tell whether it should draw a radius when an angle is 0. You can make Circle draw a radius by specifying the equivalent angle p.
The Circle method also requires that its angles lie between 2 * p and 2 * p. If you specify an angle outside this range, Visual Basic generates an error.
The PieSlice subroutine shown in the following code makes drawing pie slices easier. While either angle is greater than 2 * p, that routine subtracts 2 * p from the angle. Then, while either angle is less than or equal to 0, the routine adds 2 * p to that angle. This ensures that both angles are positive, between 0 and 2 * p, and not exactly 0. The routine then uses Circle as usual to draw the pie slice.
e10a6a0a59f035e870d90cca05b85fce.gif
' Draw a pie slice.
Public Sub PieSlice(ByVal obj As Object, _

    ByVal X As Single, ByVal Y As Single, ByVal radius As Single, _ 
    ByVal start_angle As Single, ByVal end_angle As Single) 

    ' Make both angles <= 2 * 
p.
    Do While start_angle > 2* 
p
        start_angle = start_angle - 2 * p
    Loop
    Do While end_angle > 2 * 
p
        end_angle = end_angle - 2 * p
    Loop

    ' Make both angles strictly positive.
    Do While start_angle <= 0
        start_angle = start_angle + 2 * 
p
    Loop
    Do While end_angle <= 0
        end_angle = end_angle + 2 * 
p
    Loop

    ' Draw the slice
    obj.Circle (X, Y), radius, obj.ForeColor, -start_angle, -end_angle
End Sub
Example program Pie, shown in Figure 1.8, uses the Circle method and subroutine PieSlice to draw pie slices. Enter negative values in the text boxes on the left to make the Circle method draw pie slices. Enter positive values in the right text boxes, and the PieSlice subroutine will convert them into negative values as necessary.

 
< previous page page_16 next page >